package org.qfbl.nio;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class NIOFileChannel01 {
    public static void main(String[] args) {
        String str = "hello ,ni aho 哈哈哈 "   ;
        try {
            FileOutputStream fileOutputStream = new FileOutputStream("E:\\JavaCode\\netty_project\\file\\01file.txt");

            FileChannel fileChannel = fileOutputStream.getChannel();
            // 创建一个缓存区
            ByteBuffer byteBuffer = ByteBuffer.allocate(1024) ;
            byteBuffer.put(str.getBytes());
            byteBuffer.flip();
            fileChannel.write(byteBuffer);
            fileOutputStream.close();

        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
